import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Solution {
    public List<List<Integer>> findSubsequences(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> tem = new ArrayList<>();
        backTracking(0, result, tem, nums);
        return result;
    }

    public void backTracking(int startIndex, List<List<Integer>> result, List<Integer> tem, int[] nums) {
        if (tem.size() > 1) {
            result.add(new ArrayList<>(tem));
        }
        Set<Integer> used = new HashSet<>();
        for (int i = startIndex; i < nums.length; i++) {
            if (used.contains(nums[i])) {
                continue;
            }
            if (startIndex > 0 && nums[i] < nums[startIndex - 1]) {
                continue;
            }
            used.add(nums[i]);
            tem.add(nums[i]);
            backTracking(i + 1, result, tem, nums);
            tem.remove(tem.size() - 1);
        }
    }
}
